package com.ww.springboot.dd.milvus;

import cn.hutool.http.HttpRequest;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.ww.springboot.boot.utils.json.JsonUtil;

import java.util.HashMap;
import java.util.Map;

/**
 * 描述：
 *
 * @author 🧑 ‍wanwei
 * @since 2024-05-09 16:19
 */
public class QueryDemo {

    public static void main(String[] args) {
        query();
    }

    private static void query() {
        String url = "https://image.izehui.com/PIC_800/XL/XL2250/XL2250H (2).jpg";

        byte[] bytes = HttpRequest.get(url).execute().bodyBytes();

        Map<String, Object> map = new HashMap<>();
        map.put("byteData", bytes);
        Long t = System.currentTimeMillis();
        String body = HttpRequest.post("localhost:5000/milvus/query").body(JsonUtil.toJson(map)).execute().body();
        System.out.println("耗时：" + (System.currentTimeMillis() - t));
        JSONArray data = JSON.parseObject(body).getJSONArray("data");
        System.out.println(JSON.toJSON(data));
    }

    private static void insert() {
        String url = "https://image.izehui.com/PIC_1000/LJ/LJ1331/LJ1331%20(1).jpg";

        byte[] bytes = HttpRequest.get(url).execute().bodyBytes();

        Map<String, Object> map = new HashMap<>();
        map.put("byteData", bytes);
        map.put("url", url);
        map.put("sku", "TV333SA");
        map.put("nwSku", "LKD1118");

        System.out.println(HttpRequest.post("localhost:5000/milvus/insert").body(JsonUtil.toJson(map)).execute().body());
    }
}
